﻿using System.Data;
using Entity;

namespace BUS
{
    public class ProductTypeBus
    {
        public DataTable GetAllProductType()
        {
            return CatalogueBase.GetData(ProductTypeEnt.STORE_SELECT_ALL, new string[]{}, new object[]{}).Tables[0];
        }

        public string InsertProductType(ProductType prdType)
        {
            var arg = new[] { ProductTypeEnt.FIELD_PRODUCTTYPE_CODE, ProductTypeEnt.FIELD_PRODUCTTYPE_NAME };
            var obj = new object[] { prdType.ProductTypeCode, prdType.ProductTypeName };

            return CatalogueBase.SaveData(ProductTypeEnt.STORE_INSERT, arg, obj);
        }

        public string UpdateProductType(ProductType prdType)
        {
            var arg = new[] { ProductTypeEnt.FIELD_PRODUCTTYPE_ID, ProductTypeEnt.FIELD_PRODUCTTYPE_CODE, ProductTypeEnt.FIELD_PRODUCTTYPE_NAME };
            var obj = new object[] { prdType.ProductTypeID, prdType.ProductTypeCode, prdType.ProductTypeName };

            return CatalogueBase.SaveData(ProductTypeEnt.STORE_UPDATE, arg, obj);
        }

        public DataTable GetProductTypeByCode(string code)
        {
            return CatalogueBase.GetData(ProductTypeEnt.STORE_SELECT_BY_CODE, new[] { ProductTypeEnt.FIELD_PRODUCTTYPE_CODE }, new object[] { code }).Tables[0];
        }

        public string DeleteProductType(int id)
        {
            return CatalogueBase.DeleteData(ProductTypeEnt.STORE_DELETE, new[] { ProductTypeEnt.FIELD_PRODUCTTYPE_ID }, new object[] { id });
        }

        public DataTable GetProductTypeById(int id)
        {
            return CatalogueBase.GetData(ProductTypeEnt.STORE_SELECT_BY_ID, new[] { ProductTypeEnt.FIELD_PRODUCTTYPE_ID }, new object[] { id }).Tables[0];
        }
    }
}
